package com.device.controller;

import com.device.domain.dto.CabinetTypeAddUpdateDto;
import com.device.domain.dto.CabinetTypeDto;
import com.device.domain.vo.CabinetTypeVo;
import com.device.service.CabinetTypeService;
import com.github.pagehelper.PageInfo;
import com.share.common.core.context.SecurityContextHolder;
import com.share.common.core.web.controller.BaseController;
import com.share.common.core.web.domain.AjaxResult;
import com.share.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

import static com.share.common.core.utils.PageUtils.startPage;

@RestController
@RequestMapping("/cabinetType")
public class CabinetTypeController extends BaseController {

    @Autowired
    CabinetTypeService cabinetTypeService;

    /**
     * 柜机类型查询
     * @param cabinetTypeDto
     * @return
     */
    @GetMapping("/list")
    @RequiresPermissions("device:cabinetType:list")
    public AjaxResult listOfCabinetMachineTypes(CabinetTypeDto cabinetTypeDto) {
        PageInfo<CabinetTypeVo> pageInfo = cabinetTypeService.selectListOfCabinetMachineTypes(cabinetTypeDto);
        return success(pageInfo);
    }
    /**
     * 柜机类型全查
     */
    @GetMapping("/allCheck")
    public AjaxResult allCheck(){
        return success(cabinetTypeService.allCheck());
    }

    /**
     * 柜机类型新增
     * @param cabinetTypeAddUpdateDto
     * @return
     */
    @PostMapping
    public AjaxResult refundAllCheck(@RequestBody CabinetTypeAddUpdateDto cabinetTypeAddUpdateDto){
        cabinetTypeAddUpdateDto.setCreateBy(SecurityContextHolder.getUserName());
        cabinetTypeAddUpdateDto.setCreateTime(new Date());
        cabinetTypeService.refundAllCheck(cabinetTypeAddUpdateDto);
        return success();
    }

    /**
     * 柜机类型修改
     * @param cabinetTypeAddUpdateDto
     * @return
     */
    @PutMapping
    public AjaxResult refundUpdateCheck(@RequestBody CabinetTypeAddUpdateDto cabinetTypeAddUpdateDto){
        cabinetTypeAddUpdateDto.setUpdateBy(SecurityContextHolder.getUserName());
        cabinetTypeAddUpdateDto.setUpdateTime(new Date());
        cabinetTypeService.refundUpdateCheck(cabinetTypeAddUpdateDto);
        return success();
    }
    /**
     * 删除
     */
    @DeleteMapping
    public AjaxResult delete(@RequestBody List<Long> ids){
        cabinetTypeService.typeDelete(ids);
        return success();
    }
    @DeleteMapping("/{id}")
    public AjaxResult deletedBy(@PathVariable("id") Integer id){
        cabinetTypeService.deletedBy(id);
        return AjaxResult.success();
    }


}
